package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysUserService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.dto.sys.SysUserDto;
import com.atguigu.spzx.model.entity.sys.SysUser;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@Tag(name = "用户管理模块")
@RestController
@RequestMapping("/admin/system/user")
public class SysUserController {
    @Resource
    SysUserService sysUserService;
    //接收前端请求 参数较多 可以封装DTO
    @Operation(summary = "带条件分页查询用户列表接口")
    @GetMapping("page/{pageNum}/{pageSize}")
    public Result page(@PathVariable("pageNum") Integer pageNum ,
                       @PathVariable("pageSize") Integer pageSize,
                       //get请求报文没有请求体、 可以通过pojo入参的方式获取请求参数
                       SysUserDto sysUserDto){
        PageInfo<SysUser>  pageInfo = sysUserService.page(pageNum , pageSize , sysUserDto);
        return Result.ok().data(pageInfo);
    }
    @Operation(summary = "删除用户接口")
    @DeleteMapping("deleteById/{id}")
    public Result deleteById(@PathVariable("id") Long id){
        sysUserService.deleteById(id);
        return Result.ok();
    }

    @Operation(summary = "查询用户接口")
    @GetMapping("getById/{id}")
    public Result getById(@PathVariable("id") Long id){
        SysUser sysUser = sysUserService.getById(id);
        return Result.ok().data(sysUser);
    }
    @Operation(summary = "更新用户接口")
    @PutMapping("updateById")
    public Result updateById(@RequestBody SysUser sysUser){
        sysUserService.updateById(sysUser);
        return Result.ok();
    }
    @Operation(summary = "新增用户接口")
    @PostMapping("save")
    public Result save(@RequestBody SysUser sysUser){
        sysUserService.save(sysUser);
        return Result.ok();
    }
}
